package com.by.config;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @version 1.0
 * @Author 彭彦彬
 * @Date 2025/4/2 15:02
 * @注释
 */
@Configuration
@EnableCaching // 启用缓存
public class CacheConfiguration {

    @Bean
    public CacheManager cacheManager() {
        CaffeineCacheManager cacheManager = new CaffeineCacheManager();
        cacheManager.setCaffeine(Caffeine.newBuilder()
                .maximumSize(500) // 设置缓存的最大容量
                .expireAfterWrite(10, TimeUnit.MINUTES)); // 设置写入后过期时间
        return cacheManager;
    }
}
